<?php
namespace app\home\controller;

use app\common\model\BeautyTemple as BeautyTempleModel;
/**
 * 美丽寺院控制器
 * Class Beautytemplate
 * @package app\index\controller
 */
class Beautytemplate extends Base
{
    /**
     * [index  查看]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $this->getPageAndSize($param);
        $model = new BeautyTempleModel();
        $map = [];
        try{
            if(!empty($param['con'])){
                $map['title'] = ['like', "%" . $param['con'] . "%"];
            }
            $map['status'] = 1;
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size,'id,title,cover,istop');
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
    /**
     * [getcontent  获取内容]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getcontent()
    {
        $param = input('param.');
        $model = new BeautyTempleModel();
        try{
            $data = $model->findData($param['id'],'id','title,content,intro,create_time,cover');
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1, '获取成功',$data);
    }
}